
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.3.4.4 包:com.atguigu.dataanalasis.outputformat · 大数据 bigdata_telecom_project_atguigu 课堂笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content=" 李振超">
        
        
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-change_girls/girls.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../../styles/website.css">
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="3345-53053a-com-atguigu-dataanalasis-util.html" />
    
    
    <link rel="prev" href="3343-53053a-com-atguigu-dataanalasis-mapred.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://www.atguigu.com/" target="_blank" class="custom-link">联系我们</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    第 1 章 项目背景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../../chapter1.html">
            
                <a href="../../../chapter1.html">
            
                    
                    第 2 章 项目架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../../di-3-zhang-xiang-shi-xian.html">
            
                <a href="../../../di-3-zhang-xiang-shi-xian.html">
            
                    
                    第 3 章 项目实现
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../31-shu-ju-sheng-cheng.html">
            
                <a href="../../31-shu-ju-sheng-cheng.html">
            
                    
                    3.1 数据生产模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../32-shu-ju-cai-ji-he-xiao-fei.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei.html">
            
                    
                    3.2 数据采集和消费
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/321-shu-ju-cai-ji.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/321-shu-ju-cai-ji.html">
            
                    
                    3.2.1 数据采集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei.html">
            
                    
                    3.2.2 数据消费
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.2.1" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3221-7c7b3a-propertyutil.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3221-7c7b3a-propertyutil.html">
            
                    
                    3.2.2.1 类:PropertyUtil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2.2" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3222-7c7b3ahbasedao.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3222-7c7b3ahbasedao.html">
            
                    
                    3.2.2.2 类: HBaseDao
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2.3" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3223-7c7b3ahbaseutil.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3223-7c7b3ahbaseutil.html">
            
                    
                    3.2.2.3 类: HBaseUtil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2.4" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3224-7c7b3ahbaseconsumer.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/322-shu-ju-xiao-fei/3224-7c7b3ahbaseconsumer.html">
            
                    
                    3.2.2.4 类: HBaseConsumer
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2.3" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-1.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-1.html">
            
                    
                    3.2.3 数据查询方式1
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.3.1" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-1/3231-hbasefilterutil.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-1/3231-hbasefilterutil.html">
            
                    
                    3.2.3.1 类: HBaseFilterUtil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.3.2" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-1/3232-7c7b3a-querywithfilter.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-1/3232-7c7b3a-querywithfilter.html">
            
                    
                    3.2.3.2 类: QueryWithFilter
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2.4" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-2.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-2.html">
            
                    
                    3.2.4 数据查询方式2
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.4.1" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-2/3241-shou-dong-cha-ru-bei-jiao-xin-xi.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-2/3241-shou-dong-cha-ru-bei-jiao-xin-xi.html">
            
                    
                    3.2.4.1 手动写入被叫信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.4.2" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-2/3242-shi-yong-xie-chu-li-qi-xie-ru-bei-jiao-xin-xi.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/323-shu-ju-cha-xun-fang-shi-2/3242-shi-yong-xie-chu-li-qi-xie-ru-bei-jiao-xin-xi.html">
            
                    
                    3.2.4.2 使用协处理器写入被叫信息
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2.5" data-path="../../32-shu-ju-cai-ji-he-xiao-fei/325-ba-zheng-ge-xiao-fei-mo-kuai-da-bao-dao-ji-qun-zhong-yun-xing.html">
            
                <a href="../../32-shu-ju-cai-ji-he-xiao-fei/325-ba-zheng-ge-xiao-fei-mo-kuai-da-bao-dao-ji-qun-zhong-yun-xing.html">
            
                    
                    3.2.5 把整个消费模块打包到集群中运行
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../33-shu-ju-fen-xi.html">
            
                <a href="../../33-shu-ju-fen-xi.html">
            
                    
                    3.3 数据分析
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.1" data-path="../331-xu-qiu-fen-xi.html">
            
                <a href="../331-xu-qiu-fen-xi.html">
            
                    
                    3.3.1 数据分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2" data-path="../332-mysql-biao-jie-gou-she-ji.html">
            
                <a href="../332-mysql-biao-jie-gou-she-ji.html">
            
                    
                    3.3.2 Mysql 表结构设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.3" data-path="../333-huan-jing-da-jian.html">
            
                <a href="../333-huan-jing-da-jian.html">
            
                    
                    3.3.3 环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.4" data-path="../334-xu-qiu-shi-xian.html">
            
                <a href="../334-xu-qiu-shi-xian.html">
            
                    
                    3.3.4 需求实现
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.4.1" data-path="3341-53053a-com-atguigu-dataanalasis-bean.html">
            
                <a href="3341-53053a-com-atguigu-dataanalasis-bean.html">
            
                    
                    3.3.4.1 包: com.atguigu.dataanalasis.bean
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.4.2" data-path="3342-53053a-com-atguigu-dataanalasis-conversion.html">
            
                <a href="3342-53053a-com-atguigu-dataanalasis-conversion.html">
            
                    
                    3.3.4.2 包: com.atguigu.dataanalasis.conversion
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.4.3" data-path="3343-53053a-com-atguigu-dataanalasis-mapred.html">
            
                <a href="3343-53053a-com-atguigu-dataanalasis-mapred.html">
            
                    
                    3.3.4.3 包:com.atguigu.dataanalasis.mapred
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.3.4.4" data-path="3344-53053a-com-atguigu-dataanalasis-outputformat.html">
            
                <a href="3344-53053a-com-atguigu-dataanalasis-outputformat.html">
            
                    
                    3.3.4.4 包:com.atguigu.dataanalasis.outputformat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.4.5" data-path="3345-53053a-com-atguigu-dataanalasis-util.html">
            
                <a href="3345-53053a-com-atguigu-dataanalasis-util.html">
            
                    
                    3.3.4.5 包: com.atguigu.dataanalasis.util
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3.5" data-path="../335-yun-xing-ce-shi.html">
            
                <a href="../335-yun-xing-ce-shi.html">
            
                    
                    3.3.5 运行测试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../34-shu-ju-zhan-shi.html">
            
                <a href="../../34-shu-ju-zhan-shi.html">
            
                    
                    3.4 数据展示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >3.3.4.4 包:com.atguigu.dataanalasis.outputformat</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="3344-&#x5305;comatguigudataanalasisoutputformat">3.3.4.4 &#x5305;:<code>com.atguigu.dataanalasis.outputformat</code></h1>
<h2 id="1-&#x7C7B;-mysqloutput">1. &#x7C7B;: <code>MysqlOutput</code></h2>
<p>&#x56E0;&#x4E3A;&#x662F;&#x8F93;&#x51FA;&#x5230; Mysql, &#x6240;&#x4EE5;&#x9700;&#x8981;&#x81EA;&#x5B9A;&#x4E49; <code>OutputFormat</code></p>
<pre class="language-"><code class="lang-java"><span class="token keyword">package</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dataanalasis<span class="token punctuation">.</span>outputformat<span class="token punctuation">;</span>

<span class="token keyword">import</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dataanalasis<span class="token punctuation">.</span>bean<span class="token punctuation">.</span>CommonDimension<span class="token punctuation">;</span>
<span class="token keyword">import</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dataanalasis<span class="token punctuation">.</span>bean<span class="token punctuation">.</span>CountDurationValue<span class="token punctuation">;</span>
<span class="token keyword">import</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dataanalasis<span class="token punctuation">.</span>util<span class="token punctuation">.</span>JDBCUtil<span class="token punctuation">;</span>
<span class="token keyword">import</span> com<span class="token punctuation">.</span>atguigu<span class="token punctuation">.</span>dataanalasis<span class="token punctuation">.</span>conversion<span class="token punctuation">.</span>DimensionConversion<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>hadoop<span class="token punctuation">.</span>fs<span class="token punctuation">.</span>Path<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>hadoop<span class="token punctuation">.</span>mapreduce<span class="token punctuation">.</span>*<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>hadoop<span class="token punctuation">.</span>mapreduce<span class="token punctuation">.</span>lib<span class="token punctuation">.</span>output<span class="token punctuation">.</span>FileOutputCommitter<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>hadoop<span class="token punctuation">.</span>mapreduce<span class="token punctuation">.</span>lib<span class="token punctuation">.</span>output<span class="token punctuation">.</span>FileOutputFormat<span class="token punctuation">;</span>

<span class="token keyword">import</span> java<span class="token punctuation">.</span>io<span class="token punctuation">.</span>IOException<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span>Connection<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span>PreparedStatement<span class="token punctuation">;</span>
<span class="token keyword">import</span> java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span>SQLException<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MysqlOutput</span> <span class="token keyword">extends</span> <span class="token class-name">OutputFormat</span><span class="token generics function"><span class="token punctuation">&lt;</span>CommonDimension<span class="token punctuation">,</span> CountDurationValue<span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

    <span class="token keyword">private</span> FileOutputCommitter committer<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> RecordWriter<span class="token generics function"><span class="token punctuation">&lt;</span>CommonDimension<span class="token punctuation">,</span> CountDurationValue<span class="token punctuation">&gt;</span></span> <span class="token function">getRecordWriter</span><span class="token punctuation">(</span>TaskAttemptContext context<span class="token punctuation">)</span> <span class="token keyword">throws</span> IOException<span class="token punctuation">,</span> InterruptedException <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MysqlRecordWriter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">checkOutputSpecs</span><span class="token punctuation">(</span>JobContext context<span class="token punctuation">)</span> <span class="token keyword">throws</span> IOException<span class="token punctuation">,</span> InterruptedException <span class="token punctuation">{</span>

    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> OutputCommitter <span class="token function">getOutputCommitter</span><span class="token punctuation">(</span>TaskAttemptContext context<span class="token punctuation">)</span> <span class="token keyword">throws</span> IOException<span class="token punctuation">,</span> InterruptedException <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>committer <span class="token operator">==</span> null<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            Path output <span class="token operator">=</span> FileOutputFormat<span class="token punctuation">.</span><span class="token function">getOutputPath</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">;</span>
            committer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileOutputCommitter</span><span class="token punctuation">(</span>output<span class="token punctuation">,</span> context<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> committer<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">/**
     * &#x5B9E;&#x73B0; MysqlRecordWriter &#x7C7B;
     */</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">MysqlRecordWriter</span> <span class="token keyword">extends</span> <span class="token class-name">RecordWriter</span><span class="token generics function"><span class="token punctuation">&lt;</span>CommonDimension<span class="token punctuation">,</span> CountDurationValue<span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
        <span class="token keyword">private</span> Connection conn<span class="token punctuation">;</span>
        <span class="token keyword">private</span> PreparedStatement preparedStatement<span class="token punctuation">;</span>
        <span class="token keyword">private</span> DimensionConversion conversion<span class="token punctuation">;</span>
        <span class="token keyword">private</span> String sql<span class="token punctuation">;</span>
        <span class="token keyword">private</span> <span class="token keyword">int</span> cacheBound<span class="token punctuation">;</span>
        <span class="token keyword">private</span> <span class="token keyword">int</span> count<span class="token punctuation">;</span>

        <span class="token keyword">public</span> <span class="token function">MysqlRecordWriter</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

            <span class="token keyword">try</span> <span class="token punctuation">{</span>
                conversion <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DimensionConversion</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                conn <span class="token operator">=</span> JDBCUtil<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                conn<span class="token punctuation">.</span><span class="token function">setAutoCommit</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// &#x4E0D;&#x8BA9;mysql&#x81EA;&#x52A8;&#x63D0;&#x4EA4;</span>
                sql <span class="token operator">=</span> <span class="token string">&quot;INSERT INTO tb_call VALUE(?, ?, ?, ?, ?) &quot;</span> <span class="token operator">+</span>
                        <span class="token string">&quot;ON DUPLICATE KEY &quot;</span> <span class="token operator">+</span>
                        <span class="token string">&quot;UPDATE call_count_sum=?, call_duration_sum=?&quot;</span><span class="token punctuation">;</span>
                preparedStatement <span class="token operator">=</span> conn<span class="token punctuation">.</span><span class="token function">prepareStatement</span><span class="token punctuation">(</span>sql<span class="token punctuation">)</span><span class="token punctuation">;</span>
                cacheBound <span class="token operator">=</span> <span class="token number">500</span><span class="token punctuation">;</span>
                count <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">SQLException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>

        <span class="token comment">/**
         * &#x6838;&#x5FC3;&#x7684;&#x5199;&#x51FA;&#x65B9;&#x6CD5;(&#x6570;&#x636E;&#x5199;&#x5230; Mysql)
         *
         * @param key
         * @param value
         * @throws IOException
         * @throws InterruptedException
         */</span>
        <span class="token annotation punctuation">@Override</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">write</span><span class="token punctuation">(</span>CommonDimension key<span class="token punctuation">,</span> CountDurationValue value<span class="token punctuation">)</span> <span class="token keyword">throws</span> IOException<span class="token punctuation">,</span> InterruptedException <span class="token punctuation">{</span>
            <span class="token keyword">try</span> <span class="token punctuation">{</span>
                <span class="token comment">// &#x83B7;&#x53D6;&#x8054;&#x7CFB;&#x4EBA;&#x7EF4;&#x5EA6;&#x7684;id&#x548C;&#x65F6;&#x95F4;&#x7EF4;&#x5EA6;&#x7684;id</span>
                <span class="token keyword">int</span> contactId <span class="token operator">=</span> conversion<span class="token punctuation">.</span><span class="token function">getDimensionId</span><span class="token punctuation">(</span>key<span class="token punctuation">.</span><span class="token function">getContactDimension</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">int</span> dateId <span class="token operator">=</span> conversion<span class="token punctuation">.</span><span class="token function">getDimensionId</span><span class="token punctuation">(</span>key<span class="token punctuation">.</span><span class="token function">getDateDimension</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// &#x83B7;&#x53D6;&#x901A;&#x8BDD;&#x6B21;&#x6570;</span>
                <span class="token keyword">int</span> countSum <span class="token operator">=</span> value<span class="token punctuation">.</span><span class="token function">getCountSum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// &#x83B7;&#x53D6;&#x901A;&#x8BDD;&#x65F6;&#x957F;</span>
                <span class="token keyword">int</span> durationSum <span class="token operator">=</span> value<span class="token punctuation">.</span><span class="token function">getDurationSum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// &#x62FC;&#x63A5;&#x4E3B;&#x8868;&#x7684; id_data_contact &#x5217;&#x7684;&#x503C;</span>
                String idDataContact <span class="token operator">=</span> contactId <span class="token operator">+</span> <span class="token string">&quot;_&quot;</span> <span class="token operator">+</span> dateId<span class="token punctuation">;</span>

                preparedStatement<span class="token punctuation">.</span><span class="token function">setString</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> idDataContact<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">setInt</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> dateId<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">setInt</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> contactId<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">setInt</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> countSum<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">setInt</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> durationSum<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">setInt</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">,</span> countSum<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">setInt</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">,</span> durationSum<span class="token punctuation">)</span><span class="token punctuation">;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">addBatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                count<span class="token operator">++</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>count <span class="token operator">&gt;=</span> cacheBound<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    preparedStatement<span class="token punctuation">.</span><span class="token function">executeBatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    conn<span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    count <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

            <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">SQLException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

        <span class="token punctuation">}</span>

        <span class="token annotation punctuation">@Override</span>
        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span>TaskAttemptContext context<span class="token punctuation">)</span> <span class="token keyword">throws</span> IOException<span class="token punctuation">,</span> InterruptedException <span class="token punctuation">{</span>
            <span class="token comment">// &#x6536;&#x5C3E;&#x5DE5;&#x4F5C;, &#x5C06;&#x6B8B;&#x7559;&#x7684;&#x6570;&#x636E;&#x63D0;&#x4EA4;</span>
            <span class="token keyword">try</span> <span class="token punctuation">{</span>
                <span class="token comment">//&#x5728;&#x5173;&#x95ED;&#x8D44;&#x6E90;&#x4E4B;&#x524D;, &#x5148;&#x6267;&#x884C;&#x5E76;&#x63D0;&#x4EA4;&#x6570;&#x636E;</span>
                preparedStatement<span class="token punctuation">.</span><span class="token function">executeBatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                conn<span class="token punctuation">.</span><span class="token function">commit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">SQLException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            JDBCUtil<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span>null<span class="token punctuation">,</span> preparedStatement<span class="token punctuation">,</span> conn<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x5C1A;&#x7845;&#x8C37;&#x5927;&#x6570;&#x636E; 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification"><br>&#x8BE5;&#x6587;&#x4EF6;&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2018-12-27 21:03:12
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="3343-53053a-com-atguigu-dataanalasis-mapred.html" class="navigation navigation-prev " aria-label="Previous page: 3.3.4.3 包:com.atguigu.dataanalasis.mapred">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="3345-53053a-com-atguigu-dataanalasis-util.html" class="navigation navigation-next " aria-label="Next page: 3.3.4.5 包: com.atguigu.dataanalasis.util">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.3.4.4 包:com.atguigu.dataanalasis.outputformat","level":"1.3.3.4.4","depth":4,"next":{"title":"3.3.4.5 包: com.atguigu.dataanalasis.util","level":"1.3.3.4.5","depth":4,"path":"di-3-zhang-xiang-shi-xian/33-shu-ju-fen-xi/334-xu-qiu-shi-xian/3345-53053a-com-atguigu-dataanalasis-util.md","ref":"di-3-zhang-xiang-shi-xian/33-shu-ju-fen-xi/334-xu-qiu-shi-xian/3345-53053a-com-atguigu-dataanalasis-util.md","articles":[]},"previous":{"title":"3.3.4.3 包:com.atguigu.dataanalasis.mapred","level":"1.3.3.4.3","depth":4,"path":"di-3-zhang-xiang-shi-xian/33-shu-ju-fen-xi/334-xu-qiu-shi-xian/3343-53053a-com-atguigu-dataanalasis-mapred.md","ref":"di-3-zhang-xiang-shi-xian/33-shu-ju-fen-xi/334-xu-qiu-shi-xian/3343-53053a-com-atguigu-dataanalasis-mapred.md","articles":[]},"dir":"ltr"},"config":{"plugins":["splitter","expandable-chapters-small","page-toc-button","-highlight","prism","prism-themes","tbfed-pagefooter","sitemap","change_girls","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 尚硅谷大数据 2019","modify_label":"<br>该文件最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"disqus":{"shortName":"zhenchao125"},"livereload":{},"splitter":{},"change_girls":{"time":30,"urls":["http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/62171757.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/83394736.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3394270.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/65028582.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/20359261.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/37472401.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3355397.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/11075549.jpg-atguiguImg"]},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"sitemap":{"hostname":"http://bigdataatguigu.applinzi.com/"},"page-toc-button":{"maxTocDepth":3,"minTocSize":2},"prism-themes":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":" 李振超","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"大数据 bigdata_telecom_project_atguigu 课堂笔记","language":"zh-hans","links":{"sidebar":{"联系我们":"http://www.atguigu.com/"}},"gitbook":"*","description":"课堂笔记,学生提前预习"},"file":{"path":"di-3-zhang-xiang-shi-xian/33-shu-ju-fen-xi/334-xu-qiu-shi-xian/3344-53053a-com-atguigu-dataanalasis-outputformat.md","mtime":"2018-12-27T13:03:12.185Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-11T00:27:37.149Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-change_girls/girls.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

